package clock._11.krylova;

import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.io.InputStream;

public class ClockFrame extends JFrame {

    public ClockFrame() {
        Font f = null;
        try {
            InputStream fontStr = ClockPanel.class.getResourceAsStream("Fonts/BRADHITC.ttf");
            f = Font.createFont(Font.TRUETYPE_FONT, fontStr);
            f = f.deriveFont(Font.BOLD, 24);
        } catch (FontFormatException e) {
            System.out.println("Cannot find font!!");
        } catch (IOException e) {
            System.out.println("Unknown path!");
        }
        GraphicsEnvironment.getLocalGraphicsEnvironment().registerFont(f);

        final ClockPanel rect = new ClockPanel();
        rect.setFont(f);
        setTitle("Clock");
        setLocationRelativeTo(null);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setSize(400, 400);
        JPanel butPanel = new JPanel();
        JButton hourBut = new JButton("Set hours");
        JButton minBut = new JButton("Set minutes");
        JButton secBut = new JButton("Set seconds");
        butPanel.add(hourBut);
        butPanel.add(minBut);
        butPanel.add(secBut);
        BorderLayout bl = new BorderLayout();
        setLayout(bl);

        add(butPanel, BorderLayout.NORTH);
        add(rect, BorderLayout.CENTER);

        Timer t = new Timer(1000, new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                rect.repaint();
            }
        });
        t.start();
        setVisible(true);
    }

}
